package com.cbs.android.datepick.datepickapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.cbs.android.function.datepick.CalendarDialogFragment;
import com.cbs.utils.F;
import com.cbs.utils.S;

public class DatepickerActivity extends AppCompatActivity {
    private String date;
    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_datepicker);

        date = F.Date.format(S.getTimeStamp(), "yyyy-MM-dd");
        tv = (TextView) findViewById(R.id.tv);

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CalendarDialogFragment calendarDialogFragment = new CalendarDialogFragment();
                calendarDialogFragment.setDate(date);
                calendarDialogFragment.setDateSelectListener(new CalendarDialogFragment.DateSelectListener() {
                    @Override
                    public void onSelect(String date) {
                        DatepickerActivity.this.date = date;
                        tv.setText("您选择了："+date);
                    }
                });
                calendarDialogFragment.show(getSupportFragmentManager(), "Calendar");
            }
        });
    }
}
